#! /bin/sh

if [ $# -lt 2 ]; then
    echo "Sintaxe: `basename $0` arq-marca-dagua arq-img"
    exit 10
fi

marca_dagua="$1"

full_file_name="$2"

# marca d'água existe?
if [ ! -f "$marca_dagua" ]; then
    echo "Arquivo de marca d'agua $marca_dagua nao encontrado"
    exit 20
fi

# imagem existe?
if [ ! -f "$full_file_name" ]; then
    echo "Arquivo de imagem $full_file_name nao encontrado"
    exit 30
fi

new_file_name=$PWD/`basename $full_file_name`
cp -f $full_file_name $new_file_name 2> /dev/null

echo -n "$new_file_name "

# was a frame already added?
echo "$new_file_name" | grep M_ 2> /dev/null > /dev/null
if [ $? -eq 0 ]; then
    echo " possui moldura! A marca d'agua tem que ser aplicada antes da moldura!"
else
    composite -dissolve 25% -gravity SouthWest $marca_dagua $new_file_name $new_file_name
fi 



